package pl.poznan.put.cs.idss.students.coolring.ui;

import java.awt.Image;
import java.awt.Toolkit;
import java.util.logging.Logger;

import javax.swing.JFrame;

import pl.poznan.put.cs.idss.students.coolring.i18n.Messages;
import pl.poznan.put.cs.idss.students.coolring.properties.Properties;
import pl.poznan.put.cs.idss.students.coolring.ui.components.ColorPicker;
import pl.poznan.put.cs.idss.students.coolring.ui.components.MainCanvas;
import pl.poznan.put.cs.idss.students.coolring.ui.components.Toolbox;

/**
 * Główne okno aplikacji. Zawiera wszystkie widoczne komponenty i obsługuje
 * akcje z powiązanych przycisków.
 * 
 * @author Kornel Lewandowski
 * 
 */
public class GeneralWindow extends JFrame {

	private static final long serialVersionUID = -6774540003020942443L;

	Logger log = Logger.getLogger("pl.poznan.put.cs.idss.students.coolring");

	private boolean isReady = false;

	private MainCanvas mainCanvas = new MainCanvas(this);
	private Toolbox toolbox = new Toolbox(this);
	private ColorPicker colorPicker = new ColorPicker(this);

	Image icon = Toolkit.getDefaultToolkit()
			.getImage(
					GeneralWindow.class.getResource(Properties
							.get("application_icon")));

	public GeneralWindow() {

		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(Properties.number("generalwindow_width"),
				Properties.number("generalwindow_height"));
		setTitle(Messages.get("UI.application_name") + " "
				+ Messages.get("UI.application_version"));
		setIconImage(icon);
		setLocationRelativeTo(null);
		setVisible(false);


		prepareToolbox();
		prepareColorPicker();
		prepareCanvas();

		isReady = true;

	}

	public void prepareToolbox() {
		add(getToolbox());
		log.info("Toolbox is ready");

	}

	public void prepareCanvas() {
		add(getCanvas());
		log.info("Canvas is ready");
	}

	public void prepareColorPicker() {
		add(getColorPicker());
		log.info("ColorPicker is ready");
	}

	public void showWindow() {
		setVisible(true);
	}

	public boolean isReady() {
		return isReady;
	}

	public MainCanvas getCanvas() {
		return mainCanvas;
	}

	public Toolbox getToolbox() {
		return toolbox;
	}

	public ColorPicker getColorPicker() {
		return colorPicker;
	}

	public void setColorPicker(ColorPicker colorPicker) {
		this.colorPicker = colorPicker;
	}

}
